//
//  LZLFindHeaderView.swift
//  swiftDemo
//
//  Created by luozhilin on 2018/9/14.
//  Copyright © 2018年 luozhilin. All rights reserved.
//

import UIKit

class LZLFindHeaderView: LZLBaseView {

    private let dataArray = ["电子书城","全民朗读","大咖主播","活动","直播微课","听单","游戏中心","边听变看","商城","0元购"]
    
    private lazy var collectionView:UICollectionView = {
        let flayLayout = UICollectionViewFlowLayout()
        flayLayout.itemSize = CGSize(width: (YYScreenWidth-30)/5, height: 90)
        flayLayout.minimumLineSpacing = 0
        flayLayout.minimumInteritemSpacing = 0
        flayLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        let collectionView = UICollectionView(frame: CGRect(x: 15, y: 0, width: YYScreenWidth-30, height: 180), collectionViewLayout: flayLayout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = UIColor.white
        collectionView.register(LZLHeaderViewCell.self, forCellWithReuseIdentifier: "findHeaderCell")
        return collectionView
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(collectionView)
        // 添加一个footerview
        let footerView = UIView()
        footerView.backgroundColor = FooterViewColor
        self.addSubview(footerView)
        footerView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(10)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension LZLFindHeaderView:UICollectionViewDataSource,UICollectionViewDelegate{
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.dataArray.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell:LZLHeaderViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "findHeaderCell", for: indexPath) as! LZLHeaderViewCell
        
        cell.dataString = self.dataArray[indexPath.row]
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        print("点击了第\(indexPath.row)个cell")
    }
}
